package com.kxq.zhuoyue.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kxq.zhuoyue.pageUtilEntity.BackList;
import com.kxq.zhuoyue.po.ClientHistory;
import com.kxq.zhuoyue.po.Clients;
import com.kxq.zhuoyue.service.ClientHistoryService;
import com.kxq.zhuoyue.util.result.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjh
 * @since 2023-09-08
 */
@RestController
@RequestMapping("/clientHistory")
public class ClientHistoryController {

    @Autowired
private ClientHistoryService clientHistoryService;

    /**
     * 获取黑名单
     * @return
     */
    @PostMapping("/getBackList")
    public AjaxResult getBackList(@RequestBody Clients clients){
        Map map = new HashMap<>();
        PageHelper.startPage(clients.getPageNum(),clients.getPageSize());
        List<BackList> backList = clientHistoryService.getBackList();
        PageInfo pageInfo = new PageInfo<>(backList);
        map.put("data",backList);
        map.put("pageNum",pageInfo.getPageNum());
        map.put("pageSize",pageInfo.getPageSize());
        return AjaxResult.success(map);
    }

    @GetMapping("/getClientFollow/{clientId}")
    public AjaxResult getById(@PathVariable String clientId){
        LambdaQueryWrapper<ClientHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ClientHistory::getClientId,clientId);
        ClientHistory one = clientHistoryService.getOne(queryWrapper);
        return AjaxResult.success(one);
    }
}

